/**
 * @author Tobias Boehm
 *
 * 09.05.2011
 */
package org.anddev.andengine.extension.tbsengine.message.client;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.UUID;

import org.anddev.andengine.extension.tbsengine.message.ICopyable;

/**
 * This client message should be used to join or leave a match. It contains a 
 * match ID, a flag to indicate if the player wants to join or leave the match
 * and a player ID.
 * 
 * @author Tobias Boehm
 *
 */
public class ClientMatchJoinLeaveRequestMessage extends AbsClientMatchMessage implements ICopyable<ClientMatchJoinLeaveRequestMessage> {
	
	private boolean mJoinMatch = false;
		
	/* (non-Javadoc)
	 * @see org.anddev.andengine.extension.multiplayer.protocol.adt.message.IMessage#getFlag()
	 */
	@Override
	public short getFlag() {
		
		return FLAG_CLIENT_MATCH_JOIN_LEAVE_REQUST;
	}
	
	/**
	 * @return the mPlayerID
	 */
	public UUID getPlayerID() {
		return mPlayerID;
	}

	
	/**
	 * @return the mIntentionType
	 */
	public boolean isJoiningMatch() {
		return mJoinMatch;
	}

	/**
	 * @param mIntentionType the mIntentionType to set
	 */
	public void setJoinMatch(final boolean pJoinMatch) {
		
		this.mJoinMatch = pJoinMatch;
	}

	/**
	 * @param matchID the matchID to set
	 */
	public void setMatchID(UUID matchID) {
		this.mMatchID = matchID;
	}

	@Override
	protected void onReadTransmissionClientMatchData(
			DataInputStream pDataInputStream) throws IOException {
		
		this.mJoinMatch = pDataInputStream.readBoolean();
	}

	@Override
	protected void onWriteTransmissionClientMatchData(
			DataOutputStream pDataOutputStream) throws IOException {
		
		pDataOutputStream.writeBoolean(this.mJoinMatch);
	}
	
	@Override
	public ClientMatchJoinLeaveRequestMessage copy() {
		
		final ClientMatchJoinLeaveRequestMessage copy = new ClientMatchJoinLeaveRequestMessage();
		
		copy.mJoinMatch = this.mJoinMatch;
		copy.mMatchID = this.mMatchID;
		copy.mPlayerID = this.mPlayerID;
		
		return copy;
	}
}
